package homework.printyourself.danmu.view;

import homework.printyourself.danmu.util.ColorUtil;

import javax.swing.JLabel;
import java.awt.Font;

public class DanMuLabel extends JLabel {
	
	private int speed = 1;

    public DanMuLabel(String content, String hexColor) {
        super(content);

        setFont(new Font("微软雅黑", Font.BOLD, 18));
        // XXX: 根据文字大小计算Label宽度可能存在问题
        setSize(18*content.length(), 18);

        if(hexColor != null)
            setForeground(ColorUtil.fromHexString(hexColor));
        else
            setForeground(ColorUtil.getRandomColor());
    }

    public int getSpeed() {
        return speed;
    }

    public DanMuLabel setSpeed(int s) {
        speed = s <= 0? 1: s;
        return this;
    }
}
